package cn.teamwork.ssm.controller;

import cn.teamwork.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    private UserService service;
    @ResponseBody
    @RequestMapping("check")
    public Long check(String username, String password, HttpServletRequest request) {
        Long id=service.checkUsernameAndPassword(username, password);

        HttpSession session = request.getSession();
        if(id!=null&&id>0){
            session.setAttribute("UID",id);
        }
        return  id;
    }

    @RequestMapping("login")
    public String loginPage() {
        return "login";
    }
}

